<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no">
    <meta http-equiv="X-UA-Compatible" content="ie=edge,chrome=1">
    <meta name="referrer" content="never">
    <title>判断类型的方式</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        ul {
            list-style: none;
        }
    </style>
</head>
<body>
    
    <script type="text/javascript">
        /* 
        
        */

        var obj = {};

        console.log(type(obj));
        console.log(type("hello"));
        console.log(type(123));
        console.log(type(true));
        console.log(type(undefined));
        console.log(type(NaN));
        console.log(type(null));
        console.log(type([]));
        console.log(type(new Date()));
        console.log(type(/a/));

        if(type("hello") === "string"){
            console.log("是字符串");
        }

        function type(v){
            // return Object.prototype.toString.call(v).slice(8, -1);
            return Object.prototype.toString.call(v).match(/\w+(?=\])/)[0].toLowerCase();
        }
    </script>
</body>
</html>